from gm.api import *
import talib
import numpy as np
import matplotlib.pyplot as plt

set_token('90be3f863b23ab3c1ef68d1f9b8dc06e4bebb30d')

symbol = 'SZSE.002129'
frequency = '3600' + 's'
end_time = '2017-12-31'

fields = 'open,high,low,close,volume'
last_day = get_previous_trading_date('SZSE', end_time)

data = history_n(symbol=symbol,
                 frequency=frequency,
                 count=100,
                 end_time=end_time,
                 fields=fields,
                 fill_missing='last',
                 adjust=ADJUST_PREV,
                 df=True
                 )

close = np.asarray(data['close'].values)
open = np.asarray(data['open'].values)
high = np.asarray(data['high'].values)
low = np.asarray(data['low'].values)
volume = np.asarray(data['volume'].values).astype(np.double)

upperband, middleband, lowerband = talib.BBANDS(close)

plt.plot(upperband, 'r', close, 'b--', lowerband, 'r')
plt.show()
